package com.mkk.pro.utils

import android.app.Activity
import android.content.Context
import android.util.DisplayMetrics
import android.view.inputmethod.InputMethodManager

object AppUtils {
    /**
     * 关闭键盘
     *
     * @param activity
     */
    fun closeSoftKeyboard(activity: Activity) {
        val currentFocusView = activity.currentFocus
        if (currentFocusView != null) {
            val imm = activity.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
            imm.hideSoftInputFromWindow(currentFocusView.windowToken, 0)
        }
    }

    /**
     * 获取整个屏幕的宽度
     *
     * @param context
     * @return 宽度px
     */
    fun getWidth(context: Context): Int {
        return initScreen(context).widthPixels
    }

    private fun initScreen(context: Context): DisplayMetrics {
        return context.resources.displayMetrics
    }
}